//
//

#import "MBProgressHUD+TC.h"
#import "TCConfiguration.h"
#import "UIColor+ICT.h"

@implementation MBProgressHUD(TC)
+ (MBProgressHUD *)hubWithTitle:(NSString *)title
                         second:(NSInteger)second
                         toView:(UIView *)view
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.removeFromSuperViewOnHide = YES;
    hud.labelText = title;
    hud.mode = MBProgressHUDModeText;
    [hud showAnimated:YES whileExecutingBlock:^{
        [NSThread sleepForTimeInterval:second];
    } completionBlock:^{
        [hud removeFromSuperview];
    }];
    return hud;
}

+ (MBProgressHUD *)addProgressLoadingAddToView:(UIView *)view
{
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithFrame:CGRectMake(0,
                                                                         0,
                                                                         UI_SCREEN_WIDTH,
                                                                         UI_SCREEN_HEIGHT - 64)];
    hud.color = [UIColor colorWithWhite:1 alpha:0.9];
    hud.customView = [[self class] YWKLoadingImgV];
    hud.mode = MBProgressHUDModeCustomView;
    hud.removeFromSuperViewOnHide = YES;
    [view addSubview:hud];
    [hud show:YES];
    
    return hud;
}



+ (UIImageView *)YWKLoadingImgV
{
    UIImage *image = [UIImage imageNamed:@"loading"];
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                           0,
                                                                           image.size.width,
                                                                           image.size.height)];
    //    imageview.backgroundColor = [UIColor clearColor];
    NSMutableArray *images = [NSMutableArray arrayWithCapacity:8];
    for (int index = 1; index < 13; index ++)
    {
        [images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"loading%zd",index]]];
    }
    imageview.animationImages = images;
    imageview.animationDuration = 1;
    imageview.animationRepeatCount = -1;
    [imageview startAnimating];
    
    return imageview;
}

+ (MBProgressHUD *)YWKProgressLoading
{
    //    MBProgressHUD *hud = [[MBProgressHUD alloc] init];
    MBProgressHUD *hud = [[MBProgressHUD alloc] init];
    hud.color = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.8];
    hud.minSize = CGSizeMake(50.f, 50.f);
    
    hud.customView = [[self class] YWKLoadingImgV];
    hud.mode = MBProgressHUDModeCustomView;
    
    return hud;
}

+ (MBProgressHUD *)YWKProgressLoadingInView:(UIView *)view{
    
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view];
    
    CGPoint centerScreen = CGPointMake(UI_SCREEN_WIDTH / 2, UI_SCREEN_HEIGHT / 2);
    CGPoint centerView = view.center;
    hud.xOffset = centerView.x - centerScreen.x;
    hud.yOffset = centerView.y - centerScreen.y + 64;
    
    hud.color = [UIColor colorWithWhite:1 alpha:0.9];
    hud.customView = [[self class] YWKLoadingImgV];
    hud.mode = MBProgressHUDModeCustomView;
    hud.removeFromSuperViewOnHide = YES;
    
    return hud;
}

+ (MBProgressHUD *)hubWithTitle:(NSString *)title toView:(UIView *)view
{
    MBProgressHUD *hub = [[MBProgressHUD alloc] initWithView:view];
    hub.mode = MBProgressHUDModeText;
    hub.removeFromSuperViewOnHide = YES;
    hub.detailsLabelText = title;
    hub.detailsLabelColor = [UIColor blackColor];
    hub.detailsLabelFont = [UIFont fontWithName:kTextFontName size:16.f];
    hub.labelColor = [UIColor blackColor];
    hub.animationType = MBProgressHUDAnimationFade;
    hub.color = [UIColor colorWithWhite:1 alpha:0.8];
    
    [view addSubview:hub];
    [hub show:YES];
    [hub hide:YES afterDelay:2];
    return hub;
}

@end
